﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace Asset_Service_Layer
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }
        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        //public Model.User EnterUser(string UserName, string Password)
        //{
           
            
        //    //Model.User user = new Model.User();
                
        //    // user.enterUser(UserName, Password);
        //    //user.Username = UserName;
        //    //user.Password = Password;

        //    //user = Login(UserName, Password);
        //    //user = Model.User.
            
        //    //return user;
        //}

        public Model.User Login(string Username, string Password)
        {
            Model.User user = new Model.User(Username, Password);

            if (user.PKID > 0)
            {
                return user;
            }
            else
            {
                return null;
            }
            //should also return user information and ID for asset querys later in production
            //return true; <- not needed now.   
     
         
        }
        public DataTable GetParentNodes(Int32 UserID)
        {
            SqlConnection conn = new SqlConnection(Properties.Settings.Default.DBConn);
            conn.Open();
            SqlCommand cmd = new SqlCommand("ReturnParentNodes", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];            
        }
        public DataTable GetChildNodes(string MetaData)
        {
            SqlConnection conn = new SqlConnection(Properties.Settings.Default.DBConn);
            conn.Open();
            SqlCommand cmd = new SqlCommand("ReturnChildNodes", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Meta", SqlDbType.VarChar).Value = MetaData;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];
        }


    }
}
